﻿
using LxCFD;
using Prism.Mvvm;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace TimeSolve
{
    public partial class MeshVM
    {
        public class ThreadVM : BindableBase
        {
            public ThreadVM(ZoneVM ownerZone, FvThread thread)
            {
                this.ownerZone = ownerZone;
                this.thread = thread;
            }
            FvThread thread;
            public ZoneVM ownerZone { get => _ownerZone; set { _ownerZone = value; RaisePropertyChanged("ownerZone"); } }
            private ZoneVM _ownerZone;
            #region  头
            public string name
            {
                get => thread.name;
                set
                {
                    thread.name = value;
                    RaisePropertyChanged("name");
                }
            }
            public int ID
            {
                get => thread.ID;
                set
                {
                    thread.ID = value;
                    RaisePropertyChanged("ID");
                }
            }
            #endregion
            #region 几何信息
            // public IndexNumber ThreadIndex { get; set; }

            //public bool isInner { get; set; } = false;//是否是zone中的内部面，true为边界面
            public ContactVM inContact { get => _inContact; set { _inContact = value; RaisePropertyChanged("inContact"); } }
            private ContactVM _inContact;

            #endregion
            #region 物理模型设置
            public static ObservableCollection<BoundaryTypes> SolidBoundTypes = new ObservableCollection<BoundaryTypes>()
            {
                BoundaryTypes.SolidWall
            };
            public static ObservableCollection<BoundaryTypes> FluidBoundTypes = new ObservableCollection<BoundaryTypes>()
            {
                BoundaryTypes.FluidWall,
                BoundaryTypes.VelocityInlet,
                BoundaryTypes.PressureInOut,
                BoundaryTypes.Symmetry,
            };
            public static ObservableCollection<BoundaryTypes> CoupledFluidBoundTypes = new ObservableCollection<BoundaryTypes>()
            {
                BoundaryTypes.FluidWall,
            };
            public ObservableCollection<BoundaryTypes> avaliableBoundaryTypes { get; set; } = new ObservableCollection<BoundaryTypes>();
            public void updateAvailableBoundaryTypes()
            {
                if (thread.RootZone.PhysicalModel == null) return;
                if (thread.RootZone.PhysicalModel.PhysicalType == PhysicalTypes.Solid)
                {
                    avaliableBoundaryTypes = SolidBoundTypes;

                }
                else if (thread.RootZone.PhysicalModel.PhysicalType == PhysicalTypes.Fluid)
                {
                    if (thread.IsEnableCoupled)
                    {
                        avaliableBoundaryTypes = CoupledFluidBoundTypes;
                    }
                    else
                    {
                        avaliableBoundaryTypes = FluidBoundTypes;
                    }
                }
            }
            public bool isEnableCoupled
            {
                get => thread.IsEnableCoupled;
                set { thread.IsEnableCoupled = value; RaisePropertyChanged("isEnableCoupled"); }
            }
            public BoundaryTypes boundaryType
            {
                get => thread.BoundaryType;
                set
                {
                    thread.BoundaryType = value;
                    RaisePropertyChanged("boundaryType");
                }
            }

            public WallThermalTypes wallThermalType
            {
                get => thread.WallThermalType; set
                {
                    thread.WallThermalType = value;
                    RaisePropertyChanged("wallThermalType");
                }
            }
            public double T
            {
                get
                {
                    if (thread.Temperature is Value1Const .Double vc)

                        return vc.Number;
                    else
                        return 0;
                }
                set
                {
                    thread.Temperature = new Value1Const.Double(value);
                    RaisePropertyChanged("T");
                }
            }

            public double heatFlux
            {
                get
                {
                    if (thread.HeatFlux is Value1Const.Double vc)
                        return vc.Number;
                    else
                        return 0;
                }
                set
                {
                    thread.HeatFlux = new Value1Const.Double(value);
                    RaisePropertyChanged("heatFlux");
                }
            }

            public double coupledh
            {
                get
                {
                    if (thread.Coupledh is Value1Const.Double vc)
                        return vc.Number;
                    else
                        return 0;
                }
                set
                {
                    thread.Coupledh = new Value1Const.Double(value);
                    RaisePropertyChanged("coupledh");
                }
            }

            public double coupledT
            {
                get
                {
                    if (thread.CoupledT is Value1Const.Double vc)
                        return vc.Number;
                    else
                        return 0;
                }
                set
                {
                    thread.CoupledT = new Value1Const.Double(value);
                    RaisePropertyChanged("coupledT");
                }
            }

            public bool isNoSliping
            {
                get => thread.IsNoSlipingWall;
                set
                {
                    thread.IsNoSlipingWall = value;
                    RaisePropertyChanged("isNoSliping");
                }
            }

            public bool isStaticWall
            {
                get => thread.IsStaticWall;
                set
                {
                    thread.IsStaticWall = value;
                    RaisePropertyChanged("isStaticWall");
                }
            }

            public string VelocityString
            {
                get
                {
                    if (thread.Velocity is Value1Const.Vector v3c)
                        return v3c.Number.ToString();
                    else
                        return "自定义";
                }
                set
                {
                    Vector3d v;
                    if (Vector3d.TryParse(out v, value))
                    {
                        thread.Velocity = new Value1Const.Vector(v);
                    }
                    RaisePropertyChanged("VelocityString");
                }
            }
            public bool isNormalToBound
            {
                get => thread.IsNormalToBound;
                set
                {
                    thread.IsNormalToBound = value;
                    RaisePropertyChanged("isNormalToBound");
                }
            }

            public double VelocityMod
            {
                get
                {
                    if (thread.VelocityMagnitude is Value1Const.Double vc)
                        return vc.Number;
                    else
                        return 0;
                }
                set
                {
                    thread.VelocityMagnitude = new Value1Const.Double(value);
                    RaisePropertyChanged("VelocityMod");
                }
            }

            public double Pressure
            {
                get
                {
                    if (thread.Pressure is Value1Const.Double vc)
                        return vc.Number;
                    else
                        return 0;
                }
                set
                {
                    thread.Pressure = new Value1Const.Double(value);
                    RaisePropertyChanged("Pressure");
                }
            }

            #endregion


        }

    }

}
//if (isInner)
//{
//    if (avaliableBoundaryTypes.Count == 0)
//    {
//        avaliableBoundaryTypes.Add(BoundaryTypes.内部面);
//        boundaryType = avaliableBoundaryTypes[0];
//    }
//    return;
//} 
//public int StartFaceIndex { get; set; }
//public int EndFaceIndex { get; set; }
//public int StartCellIndex { get; set; }
//public int EndCellIndex { get; set; }
//public struct Cell
//{
//    public CellFace[] cellFaces;
//}
//public struct CellFace
//{
//    public CellFace (int threadInZone,int faceInThread)
//    {
//        this.threadInZone = threadInZone;
//        this.faceInThread = faceInThread;
//    }
//    public int threadInZone;
//    public int faceInThread;
//}

//public Zone coupledZone { get=>_coupledZone; set { _coupledZone = value;RaisePropertyChanged("coupledZone"); } }
//public Thread coupledThreaad { get=>_coupledThread; set { _coupledThread = value;RaisePropertyChanged("coupledThreaad"); } }